<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isFull? 'exit-fullscreen': 'fullscreen'" class="fullscreen" @click="enterfullscreen" />
  </div>
</template>

<script>
import fs from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFull: false
    }
  },
  created () {
    if (fs.isEnabled) {
      fs.on('change', () => {
        if (fs.isFullscreen) {
          this.isFull = true
        } else {
          this.isFull = false
        }
      })
    }
  },
  methods: {
    enterfullscreen() {
      if (!fs.isEnabled) {
        this.$message.error('浏览器不支持全屏功能！')
        return
      }
      fs.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
